<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>图片信息管理</title>
	<meta name="decorator" content="default"/>
	<%
		Object optObj = request.getAttribute("opt");
		String opt = null;
		if(optObj!=null){
			opt = (String)optObj;
		}
		if(opt!=null && opt.equals("detail")){ 
	%>
	 <script type="text/javascript">
		$(document).ready(function() {
			$(this).find("input").each(function() {
				$(this).attr("disabled", "disabled");
				}); 
			$(this).find("select").each(function() {
				$(this).attr("disabled", "disabled");
				});
		});
	</script>
	 <%
	 	}else{
	 %>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
	<%}%>
	<style>
	.imgsty{
		isplay: inline-block; width:200px;height:100px;padding: 5px;
	}
	</style>
	<script type="text/javascript">
		function ajaxFileUpload(ipt,imgStr) {
		    //图片格式验证
		    var x = ipt;
		    if (!x || !x.value) return;
		    var patn = /\.jpg$|\.jpeg$|\.png$|\.gif$/i;
		    if (!patn.test(x.value)) {
		        alert("您选择的似乎不是图像文件。");
		        x.value = "";
		        return;
		    }

		    var elementIds = [ipt,$("#scal")]; //flag为id、name属性名
		    var hiddenIpt = ipt.previousElementSibling;
		    $.ajaxFileUpload({
		        url: '${ctx}/pic/img/resize?sizeH='+$("#scal").val(), 
		        type: 'post',
		        secureuri: false, //一般设置为false
		        fileElementId: ipt.id, // 上传文件的id、name属性名
		        dataType: 'json', //返回值类型，一般设置为json、application/json
		        elementIds: elementIds, //传递参数到服务器
		        success: function (data, status) {
		            if (data.status != 200) {
		                alert("文件太大，请上传不大于5M的文件！");
		                return;
		            }else {
		                //这里为上传并做一下请求显示处理，返回的data是对应上传的文件名
		            	document.getElementById(imgStr).src = data.data
		            	hiddenIpt.value = data.data
		            }
		        },
		        error: function (data, status, e) {
		            alert(e);
		        }
		    });
		    //return false;
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/pic/bizPic">图片信息列表</a></li>
		<li class="active"><a href="${ctx}/pic/bizPic/form?id=${bizPic.id}">图片信息<shiro:hasPermission name="pic:bizPic:edit">${not empty bizPic.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="pic:bizPic:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="bizPic" action="${ctx}/pic/bizPic/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">缩放比例：</label>
			<div class="controls">
				<form:input path="resizeScal"  id="scal"  class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">缩放后地址：</label>
			<div class="controls">
				<img id="imgResizeUrlImg" alt="图像" class="imgsty" src="${not empty bizPic.imgResizeUrl?bizPic.imgResizeUrl:'/static/img/timg.jpg'}" /><br/>
				<form:input path="imgResizeUrl" class="input-xlarge "/>
				<input type="file" name="imgResizeUrlIbg" id="imgResizeUrlIbg" onchange="ajaxFileUpload(this,'imgResizeUrlImg')" class="input-middle"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图片类型：</label>
			<div class="controls">
				<form:select path="imgType" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('img_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">超链地址：</label>
			<div class="controls">
				<form:input path="hrefUrl"  class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:input path="remark"  class="input-xlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="pic:bizPic:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>